<template>
    <div class="timer-container">
      <div class="timer-label">游戏剩余时间</div>
      <div class="timer-display" :class="{ 'low-time': gameStore.timeLeft < 60 }">{{ formatted }}</div>
      <div class="timer-progress">
        <div 
          class="timer-progress-bar" 
          :style="{ width: progressPercentage + '%' }"
        ></div>
      </div>
    </div>
  </template>
  
  <script setup>
  import { computed } from 'vue'
  import { useGameStore } from '@/stores/game'
  const gameStore = useGameStore()
  
  // 格式化时间显示
  const formatted = computed(() => {
    const m = String(Math.floor(gameStore.timeLeft / 60)).padStart(2, '0')
    const s = String(gameStore.timeLeft % 60).padStart(2, '0')
    return `${m}:${s}`
  })
  
  // 计算进度百分比
  const progressPercentage = computed(() => {
    // 假设游戏总时长为180秒（3分钟）
    const totalTime = 180
    return (gameStore.timeLeft / totalTime) * 100
  })
  </script>
  
  <style scoped>
  .timer-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    gap: 8px;
  }
  
  .timer-label {
    font-size: 14px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
  }
  
  .timer-display {
    font-size: 32px;
    font-weight: bold;
    color: var(--text-primary);
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    transition: color 0.3s ease;
  }
  
  .timer-display.low-time {
    color: var(--player-red);
    animation: pulse 1s infinite;
  }
  
  .timer-progress {
    width: 60%;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    overflow: hidden;
    position: relative;
  }
  
  .timer-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary) 0%, var(--primary-light) 100%);
    transition: width 1s linear;
    position: relative;
  }
  
  .timer-progress-bar::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, transparent 0%, rgba(255, 255, 255, 0.5) 50%, transparent 100%);
    animation: shimmer 2s infinite;
  }
  
  @keyframes shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
  }
  
  @keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.8; transform: scale(1.05); }
  }
  
  @media (max-width: 480px) {
    .timer-display {
      font-size: 28px;
    }
    
    .timer-label {
      font-size: 12px;
    }
    
    .timer-progress {
      width: 80%;
    }
  }
  </style>